/**
  ******************************************************************************
  * @file    IIC.h
  * @author  Dajin Li
  * @version V0.0.1
  * @date    08-08-2015 
  * @brief   TThis file contains headers of IIC read/write  function
  *          
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; KION(SZ) R&D Center
  *
  * Licensed under KION, (the "License");
  *
  ******************************************************************************
  */
/* Includes ------------------------------------------------------------------*/

#include "stm32f10x.h"
#include "Global.h"

#ifndef __SPI_H_
#define __SPI_H_

#define DATE_FORMAT_ADDR                    1  // 1 bytes
#define HOUR_FORMAT_ADDR                    2  // 1 bytes
#define LANGUAGE_ADDR                       3  // 1 bytes
#define DISP_CLOCK_ADDR                     4  // 1 bytes
#define DAYLIGHT_SAVING_ADDR                5  // 1 bytes
#define SERVICE_PWD_ADDR                    6  // 4 bytes
#define TECH_PWD_ADDR                       9  // 4 bytes
#define BKLIGHT_ADDR                        13 // 1 bytes
#define UNIT_ADDR                           14 // 1 bytes
#define SN_ADDR                             15 // 4 bytes
#define HW_VER_ADDR                         19 // 2 bytes
#define MANUFACTER_DATE_ADDR                21 // 2 bytes


#define EE_SPI_GPIO_PORT                    GPIOB
#define EE_SPI_CS_PIN                       GPIO_Pin_12
#define EE_SPI_MOSI_PIN                     GPIO_Pin_15
#define EE_SPI_MISO_PIN                     GPIO_Pin_14
#define EE_SPI_SCK_PIN                      GPIO_Pin_13

#define EE_SPI_SCK_SOURCE                   GPIO_PinSource13
#define EE_SPI_MOSI_SOURCE                  GPIO_PinSource15
#define EE_SPI_MISO_SOURCE                  GPIO_PinSource14

#define EE_SPI_SCK_AF                       GPIO_AF_SPI2
#define EE_SPI_MISO_AF                      GPIO_AF_SPI2
#define EE_SPI_MOSI_AF                      GPIO_AF_SPI2

#define EE_SPI_DUMMY_BYTE                   0xA5

#define EE_SPI_CMD_WREN                     0x06   // write enable
#define EE_SPI_CMD_WRDI                     0x04   // write disable
#define EE_SPI_CMD_RDSR                     0x05   // read status register
#define EE_SPI_CMD_WRSR                     0x01   // write status register
#define EE_SPI_CMD_READ                     0x03   // read memory data
#define EE_SPI_CMD_WRITE                    0x02   // write memory data

#define EE_SPI_WIP_FLAG                     0x02  /* Write In Progress (WIP) flag */

/* Select EE: Chip Select pin low */
#define EE_SPI_CS_LOW()                     GPIO_ResetBits(EE_SPI_GPIO_PORT, EE_SPI_CS_PIN)
/* Deselect EE: Chip Select pin high */
#define EE_SPI_CS_HIGH()                    GPIO_SetBits(EE_SPI_GPIO_PORT, EE_SPI_CS_PIN)   

#define EE_SPI                              SPI2
#define EE_SPI_CLK                          RCC_APB1Periph_SPI2

extern void EE_SPI_Init(void);
extern void ParaInit(void);
extern void SPI_EE_ParameterWrite(u32 WriteNo);
extern void SPI_EE_ParameterRead(u32 ReadNo);
extern void EE_SPI_WriteBuffer(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite);
extern void EE_SPI_ReadBuffer(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead);
extern void EE_SPI_Write_Fixed_Data(uint8_t data, uint16_t WriteAddr, uint16_t NumByteToWrite);


#endif


